home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / PASCAL / PBBEZIER.ZIP / BEZIER.PAS next >
Encoding:
Pascal/Delphi Source File  |  1994-12-16  |  2.9 KB  |  141 lines

  1. { THIS IS A SIMPLE ROUTINE TO CALCULATE BEZIER CURVES  }
  2. { IT'S NOT OPTIMIZED! ==> JUST TO SHOW YOU THE FORMULA }
  3. { OF A BEZIER-CURVE WHICH GO THROUGH THE FOUR POINTS   }
  4. { B1 --> B4     ENJOY THEM.          -Lord Cyrix       }
  5.  
  6.  
  7. uses crt;
  8. var x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10:integer;
  9.     t,xt:real;
  10.     tel:integer;
  11.     ta,ta2,ta3,ta4:array[0..500] of integer;
  12.     ch:char;
  13.     tab,tab2:array[0..255] of integer;
  14.     b,b0,b1,b2,b3,b4,b5,b6:byte;
  15.  
  16.  
  17.  
  18. procedure vsync;assembler;
  19. asm
  20.              MOV      DX,3DAH
  21.              MOV      AH,08H
  22.  @WAIT1:     IN       AL,DX
  23.              AND      AL,AH
  24.              JNZ      @WAIT1
  25.  @WAIT2:     IN       AL,DX
  26.              AND      AL,AH
  27.              JZ       @WAIT2
  28. end;
  29.  
  30. procedure setrgb(nr,r,g,b:byte);assembler;
  31. asm
  32.  mov dx,3C8H
  33.  mov al,nr
  34.  out dx,al
  35.  inc dx
  36.  mov al,r
  37.  out dx,al
  38.  mov al,g
  39.  out dx,al
  40.  mov al,b
  41.  out dx,al
  42. end;
  43.  
  44. procedure bereken;
  45. var r,i:real;
  46.     tel3:word;
  47.     tel,tel2:byte;
  48.     nr:word;
  49.  
  50. begin
  51.  randomize;
  52.  i:=0;
  53.  r:=pi/64;
  54.  for tel:=0 to 255 do
  55.  begin
  56.   tab [tel]:=round(sin(i)*25)+20;
  57.   tab2[tel]:=round(sin(i)*25)+20;
  58.   i:=i+r;
  59.  end;
  60. end;
  61.  
  62.  
  63. procedure p(x,y,c:integer); assembler;
  64. asm
  65.     mov     ax,y
  66.     mov     bx,320
  67.     mul     bx
  68.     add     ax,x
  69.     mov     di,ax
  70.  
  71.     mov     ax,0A000h
  72.     mov     es,ax
  73.     mov     ax,c
  74.     stosb
  75. end;
  76.  
  77. procedure start;
  78. var a0,a1,a2,a3,a4,a5,a6,a7,a8,a9:byte;
  79.     t1,t2,t3,t4:array[0..199] of integer;
  80.     tt:integer;
  81. begin
  82.  randomize;
  83.  b1:=random(255); b2:=random(255); b3:=random(255); b4:=random(255); b0:=random(255);
  84.  a1:=50+random(60); a2:=50+random(60); a3:=50+random(60); a4:=50+random(60);
  85.  a5:=50+random(60); a6:=50+random(60); a7:=50+random(60); a8:=50+random(60);
  86.  a9:=50+random(60); a0:=50+random(60);
  87.  for tel:=0 to 99 do
  88.  begin
  89.   t:=t+0.01;
  90.   t1[tel]:=round((1-t)*(1-t)*(1-t)*256);
  91.   t2[tel]:=round(3*t*(1-t)*(1-t)*256);
  92.   t3[tel]:=round(3*t*t*(1-t)*256);
  93.   t4[tel]:=round(t*t*t*256);
  94.  end;
  95.  asm
  96.   mov ax,13h
  97.   int 10h
  98.  end;
  99.  
  100. repeat
  101.  inc(b1); inc(b2); inc(b3); dec(b4); inc(b0);
  102.  x0:=a0+tab2[b1]; x1:=a1+tab[b1];  x2:=a2+tab[b2];  x3:=a3+tab2[b4];
  103.  x5:=a5+tab2[b2];  x6:=a6+tab[b0];  x8:=a8+tab2[b3]; x9:=a9+tab[b0];
  104.  
  105.  if x3>x2 then x4:=x3+(x3-x2) else x4:=x3-(x2-x3);
  106.  if x6>x5 then x7:=x6+(x6-x5) else x7:=x6-(x5-x6);
  107.  if x10>x9 then x10:=x9+(x9-x8) else x10:=x9-(x8-x9);
  108.  
  109.  t:=0;
  110.  for tt:=0 to 99 do
  111.  begin
  112.   tel:=tt;
  113.   ta [tel]:=(t1[tel]*x0+t2[tel]*x1+t3[tel]*x2+t4[tel]*x3) shr 8;
  114.   ta2[tel]:=(t1[tel]*x3+t2[tel]*x4+t3[tel]*x5+t4[tel]*x6) shr 8;
  115.   ta3[tel]:=(t1[tel]*x6+t2[tel]*x7+t3[tel]*x5+t4[tel]*x6) shr 8;
  116.   p( 0+tt,ta [tel],28);
  117.   p(100+tt,ta2[tel],28);
  118.   p(200+tt,ta3[tel],28);
  119.  end;
  120.  setrgb(0,0,0,0);
  121.  vsync;
  122.  setrgb(0,60,0,0);
  123.  for tt:=0 to 99 do
  124.  begin
  125.   tel:=tt;
  126.   p( 00+tt,ta [tel],0);
  127.   p(100+tt,ta2[tel],0);
  128.   p(200+tt,ta3[tel],0);
  129.  end;
  130.  
  131. until keypressed;
  132. ch:=readkey;
  133.  
  134. end;
  135.  
  136.  
  137. begin
  138.  bereken;
  139.  start;
  140.  textmode(lastmode);
  141. end.